#include <stdio.h>
#include "Command.cpp"

class MoveUnitCommand : Command {
    public:
        MoveUnitCommand(Unit* unit, int x, int y) : unit_(unit), x_(x), y_(y), xBefore_(0), yBefore_(0){}
    
        virtual void execute(){
            xBefore_ = unit -> x_;
            yBefore_ = unit -> y_;
            unit -> moveTo(x_, y_);
        }

        virtual void undo(){
            unit -> moveTo(xBefore_, yBefore_);
        }

    private:
        Unit* unit_;
        int x_, y_;
        int xBefore_, yBefore_;
};


Unit* getSelectedUnit(){
    return new Unit();
}

Command* handleInput(){
    Unit* unit = getSelectedUnit();
    if(isPressed(BUTTON_UP){
        int destY = unit -> y() - 1;
        return new MoveUnitCommand(unit, unit -> x(), destY);
    }
    if(isPressed(BUTTON_DOWN){
        int destY = unit -> y() + 1;
        return new MoveUnitCommand(unit, unit -> x(), destY);
    }

    return NULL;
}